#pragma once

#include <time.h>
#include <iostream>
#include <string>
#include "lockqueue.h"

enum LogLevel
{
    INFO, // 普通信息
    ERROR // 错误信息
};

// mprpc框架提供的日志系统
class Logger
{
public:
    // 获取日志的单例
    static Logger& getInstance();
    // 设置日志级别
    void setLogLevel(LogLevel level);
    // 写日志
    void Log(std::string msg);

private:
    LogLevel _logLevel; // 记录日志级别
    LockQueue<std::string> _lockQueue; // 日志缓冲队列

    Logger();
    Logger(const Logger&) = delete;
    Logger& operator=(const Logger&) = delete;
};

// 定义宏
#define LOG_INFO(logMsgFormat, ...) \
    do \
    { \
        Logger& logger = Logger::getInstance(); \
        logger.setLogLevel(INFO); \
        char buf[1024] = {0}; \
        snprintf(buf, 1024, logMsgFormat, ##__VA_ARGS__); \
        logger.Log(buf); \
    } while (0);

    
#define LOG_ERROR(logMsgFormat, ...) \
    do \
    { \
        Logger& logger = Logger::getInstance(); \
        logger.setLogLevel(ERROR); \
        char buf[1024] = {0}; \
        snprintf(buf, 1024, logMsgFormat, ##__VA_ARGS__); \
        logger.Log(buf); \
    } while (0);